home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / bbs / doorinfo.zip / PLAYXWIT.C < prev    next >
C/C++ Source or Header  |  1997-05-14  |  17KB  |  628 lines

  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6. #include <time.h>
  7. #include "doorutil.h"
  8. #include "croswits.h"
  9.  
  10. void show_games(void);
  11.  
  12. char hello[] =
  13. "Welcome to CROSWITS!\r\r"
  14. "This is a word game, based on the familiar SCRABBLE game.\r"
  15. "This program is copyright by Herb Rose, 1995.\r\r";
  16.  
  17. char active[] =
  18. "Entering FALKEN CROSWITS!\r\r"
  19. "Type 'help' for an explanation of the game and a help screen.\r"
  20. "The game is like a mini-teleconference, so you can talk to the\r"
  21. "other players.\r";
  22.  
  23. struct game_rec game, game2;
  24.  
  25. struct board_rec board2[15][15] =
  26. {
  27.     '_', 0, TW, '_', 0, NL, '_', 0, NL, '_', 0, DL, '_', 0, NL,
  28.     '_', 0, NL, '_', 0, NL, '_', 0, TW, '_', 0, NL, '_', 0, NL,
  29.     '_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, NL, '_', 0, TW,
  30.  
  31.     '_', 0, NL, '_', 0, DW, '_', 0, NL, '_', 0, NL, '_', 0, NL,
  32.     '_', 0, TL, '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, TL,
  33.     '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, DW, '_', 0, NL,
  34.  
  35.     '_', 0, NL, '_', 0, NL, '_', 0, DW, '_', 0, NL, '_', 0, NL,
  36.     '_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, DL, '_', 0, NL,
  37.     '_', 0, NL, '_', 0, NL, '_', 0, DW, '_', 0, NL, '_', 0, NL,
  38.  
  39.     '_', 0, DL, '_', 0, NL, '_', 0, NL, '_', 0, DW, '_', 0, NL,
  40.     '_', 0, NL, '_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, NL,
  41.     '_', 0, NL, '_', 0, DW, '_', 0, NL, '_', 0, NL, '_', 0, DL,
  42.  
  43.     '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, DW,
  44.     '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, NL,
  45.     '_', 0, DW, '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, NL,
  46.  
  47.     '_', 0, NL, '_', 0, TL, '_', 0, NL, '_', 0, NL, '_', 0, NL,
  48.     '_', 0, TL, '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, TL,
  49.     '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, TL, '_', 0, NL,
  50.  
  51.     '_', 0, NL, '_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, NL,
  52.     '_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, DL, '_', 0, NL,
  53.     '_', 0, NL, '_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, NL,
  54.  
  55.     '_', 0, TW, '_', 0, NL, '_', 0, NL, '_', 0, DL, '_', 0, NL,
  56.     '_', 0, NL, '_', 0, NL, '_', 0, DW, '_', 0, NL, '_', 0, NL,
  57.     '_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, NL, '_', 0, TW,
  58.  
  59.     '_', 0, NL, '_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, NL,
  60.     '_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, DL, '_', 0, NL,
  61.     '_', 0, NL, '_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, NL,
  62.  
  63.     '_', 0, NL, '_', 0, TL, '_', 0, NL, '_', 0, NL, '_', 0, NL,
  64.     '_', 0, TL, '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, TL,
  65.     '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, TL, '_', 0, NL,
  66.  
  67.     '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, DW,
  68.     '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, NL,
  69.     '_', 0, DW, '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, NL,
  70.  
  71.     '_', 0, DL, '_', 0, NL, '_', 0, NL, '_', 0, DW, '_', 0, NL,
  72.     '_', 0, NL, '_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, NL,
  73.     '_', 0, NL, '_', 0, DW, '_', 0, NL, '_', 0, NL, '_', 0, DL,
  74.  
  75.     '_', 0, NL, '_', 0, NL, '_', 0, DW, '_', 0, NL, '_', 0, NL,
  76.     '_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, DL, '_', 0, NL,
  77.     '_', 0, NL, '_', 0, NL, '_', 0, DW, '_', 0, NL, '_', 0, NL,
  78.  
  79.     '_', 0, NL, '_', 0, DW, '_', 0, NL, '_', 0, NL, '_', 0, NL,
  80.     '_', 0, TL, '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, TL,
  81.     '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, DW, '_', 0, NL,
  82.  
  83.     '_', 0, TW, '_', 0, NL, '_', 0, NL, '_', 0, DL, '_', 0, NL,
  84.     '_', 0, NL, '_', 0, NL, '_', 0, TW, '_', 0, NL, '_', 0, NL,
  85.     '_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, NL, '_', 0, TW
  86. };
  87.  
  88. struct letter_rec BASE_letters[NUMLETTERS] =
  89. {
  90.     'A', 1, 0, 'A', 1, 0, 'A', 1, 0, 'A', 1, 0, 'A', 1, 0,
  91.     'A', 1, 0, 'A', 1, 0, 'A', 1, 0, 'A', 1, 0, 'B', 3, 0,
  92.     'B', 3, 0, 'C', 3, 0, 'C', 3, 0, 'D', 2, 0, 'D', 2, 0,
  93.     'D', 2, 0, 'D', 2, 0, 'E', 1, 0, 'E', 1, 0, 'E', 1, 0,
  94.     'E', 1, 0, 'E', 1, 0, 'E', 1, 0, 'E', 1, 0, 'E', 1, 0,
  95.     'E', 1, 0, 'E', 1, 0, 'E', 1, 0, 'E', 1, 0, 'F', 4, 0,
  96.     'F', 4, 0, 'G', 2, 0, 'G', 2, 0, 'G', 2, 0, 'H', 4, 0,
  97.     'H', 4, 0, 'I', 1, 0, 'I', 1, 0, 'I', 1, 0, 'I', 1, 0,
  98.     'I', 1, 0, 'I', 1, 0, 'I', 1, 0, 'I', 1, 0, 'I', 1, 0,
  99.     'J', 8, 0, 'K', 5, 0, 'L', 1, 0, 'L', 1, 0, 'L', 1, 0,
  100.     'L', 1, 0, 'M', 3, 0, 'M', 3, 0, 'N', 1, 0, 'N', 1, 0,
  101.     'N', 1, 0, 'N', 1, 0, 'N', 1, 0, 'N', 1, 0, 'O', 1, 0,
  102.     'O', 1, 0, 'O', 1, 0, 'O', 1, 0, 'O', 1, 0, 'O', 1, 0,
  103.     'O', 1, 0, 'O', 1, 0, 'P', 3, 0, 'P', 3, 0, 'Q', 10, 0,
  104.     'R', 1, 0, 'R', 1, 0, 'R', 1, 0, 'R', 1, 0, 'R', 1, 0,
  105.     'R', 1, 0, 'S', 1, 0, 'S', 1, 0, 'S', 1, 0, 'S', 1, 0,
  106.     'T', 1, 0, 'T', 1, 0, 'T', 1, 0, 'T', 1, 0, 'T', 1, 0,
  107.     'T', 1, 0, 'U', 1, 0, 'U', 1, 0, 'U', 1, 0, 'U', 1, 0,
  108.     'V', 4, 0, 'V', 4, 0, 'W', 4, 0, 'W', 4, 0, 'X', 8, 0,
  109.     'Y', 4, 0, 'Y', 4, 0, 'Z', 10, 0, '?', 0, 0, '?', 0, 0
  110. };
  111.  
  112. char wb[200];
  113.  
  114. ENTRY mkey;
  115.  
  116. char scrabname[80];
  117.  
  118. struct acct_rec ac;
  119.  
  120. struct xwit_player_rec aplayer;
  121.  
  122. char unreg_text[] =
  123. "This version of CROSWITS is unregistered, and limited to 5 games.\r"
  124. "You may not start a new game.\r\r"
  125. "To remedy this situation, please ask your SYSOP to register the game.\r\r";
  126.  
  127. int registered = 0;
  128. int dbfile;
  129.  
  130. main()
  131. {
  132.     int k, j, n, status, size, done;
  133.     int gamect;
  134.     time_t t1;
  135.     char *cp;
  136.  
  137.     init();
  138.  
  139.     t1 = time(NULL);
  140.  
  141.     send(hello);
  142.  
  143.     registered = check_registration("CROSWITS", 19866);
  144.     if (!registered)
  145.     qputs("\rThis version of CROSWITS is NOT REGISTERED.\r");
  146.  
  147.     if (myuser->u_ansi == 0)
  148.     {
  149.     send("You must have ANSI turned on to play this game.\r");
  150.     exit(0);
  151.     }
  152.  
  153.     for (;;)
  154.     {
  155.     strcpy(myuser->doors_id, "playxwit");
  156.     gamect = 0;
  157.     myuser->u_work1 = -1;    /* don't show that we are in a game. */
  158.  
  159.     j = 0;
  160.     dbfile = btrv(b_open, -1, "croswits.idx", &j, (ENTRY *) "croswits.dat", 1);
  161.     if (dbfile != -1)
  162.     {
  163.         size = sizeof(struct xwit_player_rec);
  164.         sprintf(mkey.key, "!%s", myacct->acctname);
  165.         if ((status = btrv(b_getequ, dbfile, &aplayer, &size, &mkey, 0)) == OK)
  166.         {
  167.         for (n = 0; n < 40; n++)
  168.         {
  169.             if (aplayer.games[n] > 0)
  170.             {
  171.             size = sizeof(struct game_rec);
  172.             sprintf(mkey.key, "%05d", aplayer.games[n]);
  173.             status = btrv(b_getequ, dbfile, &game, &size, &mkey, 0);
  174.                         if ((status == OK) && (gamect < 40))
  175.             {
  176.                 if ((game.game_end_time != (time_t) 0) &&
  177.                 ((t1 - game.game_end_time) > (time_t) (7L * 3600L * 24L)))
  178.                 {
  179.                 btrv(b_delete, dbfile, &game, &size, &mkey, 0);
  180.                 }
  181.                 else if (game.player[0].name[0] == '\0' &&
  182.                      game.player[1].name[0] == '\0' &&
  183.                      game.player[2].name[0] == '\0' &&
  184.                      game.player[3].name[0] == '\0')
  185.                 {
  186.                 btrv(b_delete, dbfile, &game, &size, &mkey, 0);
  187.                 }
  188.                 else
  189.                 {
  190.                 if ((strcmpi(game.player[0].name, myacct->acctname) == 0) ||
  191.                     (strcmpi(game.player[1].name, myacct->acctname) == 0) ||
  192.                     (strcmpi(game.player[2].name, myacct->acctname) == 0) ||
  193.                     (strcmpi(game.player[3].name, myacct->acctname) == 0))
  194.                 {
  195.                     if (gamect == 0)
  196.                     {
  197.                     send("Games you are currently playing :\r");
  198.                     }
  199.                                     gamect++;
  200.                     sprintf(wb, "  Game %d with ", atoi(mkey.key));
  201.                     for (j = 0; j < MAXPLAYERS; j++)
  202.                     {
  203.                     if (strlen(game.player[j].name) &&
  204.                         strcmpi(myacct->acctname, game.player[j].name))
  205.                     {
  206.                         strcat(wb, game.player[j].name);
  207.                         strcat(wb, ", ");
  208.                     }
  209.                     }
  210.                     if (game.game_end_time != 0L)
  211.                     {
  212.                     strcat(wb, "  GAME OVER.\r");
  213.                     }
  214.                     else
  215.                     {
  216.                     strcat(wb, "  it is ");
  217.                     strcat(wb, game.player[game.whose_turn].name);
  218.                     strcat(wb, "'s turn.\r");
  219.                     }
  220.                     send(wb);
  221.                 }
  222.                 }
  223.             }
  224.             else
  225.             {
  226.                 aplayer.games[n] = 0;
  227.             }
  228.             }
  229.         }
  230.         }
  231.         btrv(b_close, dbfile, &game, &size, &mkey, 0);
  232.     }
  233.  
  234.     for (done = 0; done == 0;)
  235.     {
  236.         if (gamect)
  237.         {
  238.         send("\rEnter the game number to join, or 'NEW' for a new game,\r");
  239.         }
  240.         else
  241.         {
  242.         send("You have no active games.  Enter 'NEW' to start a new game,\r");
  243.         }
  244.         send("or, enter 'LIST' to see all the active games,\r");
  245.         if (myacct->accessflags & sysopaccess)
  246.         {
  247.         send("or, enter 'DELETE x' to delete game number 'x', \r");
  248.         }
  249.         send("or, enter 'QUIT' if you choose not to play now.\r\r?");
  250.  
  251.         qgets(wb, 80);
  252.         if (wb[0] == 'q')
  253.         exit(0);
  254.         else if (wb[0] == 'l')
  255.         show_games();
  256.         else if (wb[0] == 'n')
  257.         {
  258.         done = 1;
  259.         j = -1;
  260.         }
  261.         else if (strnicmp("del", wb, 3) == 0)
  262.         {
  263.         if (myacct->accessflags & sysopaccess)
  264.         {
  265.             cp = strtok(wb, " ,");
  266.             cp = strtok(NULL, " ,");
  267.             if (cp == NULL)
  268.             {
  269.             send("Format for delete is 'delete #'.\r");
  270.             }
  271.             else
  272.             {
  273.             j = atoi(cp);
  274.             delete_game(j);
  275.             }
  276.         }
  277.         else
  278.         {
  279.             send("Only sysops can delete games.\r");
  280.         }
  281.         }
  282.         else if (isdigit(wb[0]))
  283.         {
  284.         j = atoi(wb);
  285.         if (j > 0)
  286.         {
  287.             for (k = 0; k < 40; k++)
  288.             {
  289.             if (aplayer.games[k] == j)
  290.             {
  291.                 done = 1;
  292.                 break;
  293.             }
  294.             }
  295.         }
  296.         }
  297.     }
  298.  
  299.     if (j == -1)
  300.     {
  301.         for (j = 0; ((j < 40) && (aplayer.games[j] > 0)); j++);
  302.         if (j == 40)
  303.         {
  304.         send("Too many games. You cannot start a new CROSWITS game.\r");
  305.         continue;    /* continue the for(ever) type loop */
  306.         }
  307.         memset(&game, 0, sizeof(struct game_rec));
  308.         memcpy(game.letters, BASE_letters, sizeof(BASE_letters));
  309.         memcpy(game.board, board2, sizeof(board2));
  310.         for (j = 0; j < MAXPLAYERS; j++)
  311.         {
  312.         game.player[j].line_num = -1;
  313.         }
  314.         game.letters_left = NUMLETTERS;
  315.         game.game_start_time = time(NULL);
  316.         game.game_end_time = (time_t) 0;
  317.         strcpy(game.player[0].name, myacct->acctname);
  318.         send("Please enter the names of the users who will be playing this\r");
  319.         send("game with you.  Up to 3 other players are allowed.\r");
  320.         send("Press [ENTER] after each name, and press [ENTER] on a blank\r");
  321.         send("line when done with the entries.\r");
  322.         do
  323.         {
  324.         send("\rPlayer 1 : ");
  325.         qgets(wb, 80);
  326.         if (strlen(wb) == 0)
  327.             exit(0);
  328.         if ((status = find_account(wb, &ac)) != OK)
  329.         {
  330.             send("No account for that name.\r");
  331.         }
  332.         for (j = 0; j < MAXPLAYERS; j++)
  333.         {
  334.             if (strcmpi(ac.acctname, game.player[j].name) == 0)
  335.             {
  336.             send("That player is already in the game.\r");
  337.             status = (!OK);
  338.             }
  339.         }
  340.         } while (status != OK);
  341.         strcpy(game.player[1].name, ac.acctname);
  342.         do
  343.         {
  344.         send("\rPlayer 2 : ");
  345.         qgets(wb, 80);
  346.         if (strlen(wb) == 0)
  347.             break;
  348.         if ((status = find_account(wb, &ac)) != OK)
  349.         {
  350.             send("No account for that name.\r");
  351.         }
  352.         for (j = 0; j < MAXPLAYERS; j++)
  353.         {
  354.             if (strcmpi(ac.acctname, game.player[j].name) == 0)
  355.             {
  356.             send("That player is already in the game.\r");
  357.             status = (!OK);
  358.             }
  359.         }
  360.         } while (status != OK);
  361.         if (strlen(wb) != 0)
  362.         {
  363.         strcpy(game.player[2].name, ac.acctname);
  364.         do
  365.         {
  366.             send("\rPlayer 3 : ");
  367.             qgets(wb, 80);
  368.             if (strlen(wb) == 0)
  369.             break;
  370.             if ((status = find_account(wb, &ac)) != OK)
  371.             {
  372.             send("No account for that name.\r");
  373.             }
  374.             for (j = 0; j < MAXPLAYERS; j++)
  375.             {
  376.             if (strcmpi(ac.acctname, game.player[j].name) == 0)
  377.             {
  378.                 send("That player is already in the game.\r");
  379.                 status = (!OK);
  380.             }
  381.             }
  382.         } while (status != OK);
  383.         if (strlen(wb) != 0)
  384.         {
  385.             strcpy(game.player[3].name, ac.acctname);
  386.         }
  387.         }
  388.         srand((int) time(NULL));
  389.         do
  390.         {
  391.         j = rand() % MAXPLAYERS;
  392.         } while (strlen(game.player[j].name) == 0);
  393.         game.whose_turn = j;
  394.         for (j = 0; j < 7; j++)
  395.         {
  396.         for (k = 0; k < MAXPLAYERS; k++)
  397.         {
  398.             if (strlen(game.player[k].name))
  399.             {
  400.             do
  401.             {
  402.                 status = rand() % NUMLETTERS;
  403.             } while (game.letters[status].used);
  404.             game.letters[status].used = 1;
  405.             game.player[k].letters[j] = status;
  406.             game.letters_left--;
  407.             }
  408.         }
  409.         }
  410.         if (save_new_game() == 0)
  411.         {
  412.         qputs("Error creating new game!");
  413.         exit(0);
  414.         }
  415.         j = game.game_number;
  416.         if (strlen(game.player[0].name))
  417.         setplayer(game.player[0].name, game.game_number);
  418.         if (strlen(game.player[1].name))
  419.         setplayer(game.player[1].name, game.game_number);
  420.         if (strlen(game.player[2].name))
  421.         setplayer(game.player[2].name, game.game_number);
  422.         if (strlen(game.player[3].name))
  423.         setplayer(game.player[3].name, game.game_number);
  424.     }
  425.  
  426.     send(active);        /* send a 'we are alive' to the user */
  427.     delay(1);
  428.  
  429.     hog();
  430.  
  431.     sprintf(scrabname, "croswits.exe %d", j);
  432.  
  433.     strcpy(myuser->doors_id, "CROSWITS");
  434.     myuser->u_work1 = j;
  435.     for (j = 0; j < numlines; j++)
  436.     {
  437.         if (j != who)
  438.         {
  439.         if (user[j].u_stat == 6)    /* is the guy in doors ? */
  440.         {
  441.             if ((strcmpi(user[j].doors_id, "CROSWITS") == 0) &&
  442.             (user[j].u_work1 == myuser->u_work1))
  443.             break;
  444.         }
  445.         }
  446.     }
  447.     nohog();
  448.  
  449.     if (j == numlines)    /* main prog not loaded yet! */
  450.     {
  451.         if ((j = load_a_door(scrabname, 5)) < 0)
  452.         {
  453.         sprintf(wb, "Cannot load FALKEN Scrabble!!  Err = %d\r\r", j);
  454.         send(wb);
  455.         delay(2);
  456.         exit(0);
  457.         }
  458.     }
  459.  
  460.     myuser->u_privateflag = 1;    /* no 'login' messages */
  461.     suspend();
  462.     }
  463. }
  464.  
  465. save_new_game()
  466. {
  467.     int bfile;
  468.     int msize;
  469.     int j;
  470.  
  471.     if ((bfile = btrv(b_open, -1, "croswits.idx", &msize, (ENTRY *) "croswits.dat", 1)) < 0)
  472.     bfile = btrv(b_create, -1, "croswits.idx", &msize, (ENTRY *) "croswits.dat", 1);
  473.  
  474.     if (bfile < 0)
  475.     {
  476.     send("Unable to save game in database! Code = 110\r");
  477.     return 0;
  478.     }
  479.  
  480.     msize = sizeof(struct game_rec);
  481.     if (btrv(b_gethi, bfile, &game2, &msize, &mkey, 0) != OK)
  482.     {
  483.     game.game_number = 1;
  484.     }
  485.     else
  486.     {
  487.     game.game_number = atoi(mkey.key) + 1;
  488.     if (!registered && game.game_number > 5)
  489.     {
  490.         send(unreg_text);
  491.         return 0;
  492.     }
  493.     }
  494.     sprintf(mkey.key, "%05d", game.game_number);
  495.     msize = sizeof(struct game_rec);
  496.     if (btrv(b_insert, bfile, &game, &msize, &mkey, 0) != OK)
  497.     {
  498.     btrv(b_close, bfile, &game, &msize, &mkey, 0);
  499.     send("Unable to save game in database! Code = 112\r");
  500.     return 0;
  501.     }
  502.     btrv(b_close, bfile, &game, &msize, &mkey, 0);
  503.     send("New game successfully configured and stored in database.\r");
  504.     return 1;
  505. }
  506.  
  507.  
  508. void show_games()
  509. {
  510.     int totgamect = 0;
  511.     int j;
  512.     int lines;
  513.     int status;
  514.     int msize;
  515.     int bfile;
  516.     ENTRY mkey;
  517.  
  518.     bfile = btrv(b_open, -1, "croswits.idx", &msize, (ENTRY *) "croswits.dat", 1);
  519.  
  520.     if (bfile < 0)
  521.     {
  522.     send("Unable to open game file for input!\r");
  523.     return;
  524.     }
  525.  
  526.     msize = sizeof(struct game_rec);
  527.     strcpy(mkey.key, "00000");
  528.     status = btrv(b_getge, bfile, &game, &msize, &mkey, 0);
  529.     lines = 0;
  530.     while (status == OK)
  531.     {
  532.     totgamect++;
  533.     qprintf("Game %3d : ", game.game_number);
  534.     for (j = 0; j < MAXPLAYERS; j++)
  535.     {
  536.         if (strlen(game.player[j].name))
  537.         {
  538.         qprintf("%s (%d), ", game.player[j].name,
  539.             game.player[j].score);
  540.         }
  541.     }
  542.     qprintf("   %d letters left.\r", game.letters_left);
  543.     if (++lines == 20)
  544.     {
  545.         send("\rPress [ENTER] to continue or 'Q' to quit :");
  546.         qgets(wb, 80);
  547.         if (tolower(wb[0]) == 'q')
  548.         break;
  549.         lines = 0;
  550.     }
  551.     msize = sizeof(struct game_rec);
  552.     status = btrv(b_getnext, bfile, &game, &msize, &mkey, 0);
  553.     }
  554.     qprintf("%d games listed.\r\r", totgamect);
  555.     btrv(b_close, bfile, "croswits.idx", &msize, (ENTRY *) "croswits.dat", 1);
  556. }
  557.  
  558. delete_game(int gamenum)
  559. {
  560.     int j;
  561.     int bfile, msize;
  562.  
  563.     bfile = btrv(b_open, -1, "croswits.idx", &msize, (ENTRY *) "croswits.dat", 1);
  564.  
  565.     if (bfile < 0)
  566.     {
  567.     qprintf("Unable to open game file for dlete!\r");
  568.     return;
  569.     }
  570.  
  571.     msize = sizeof(struct game_rec);
  572.     sprintf(mkey.key, "%05d", gamenum);
  573.     if (btrv(b_getequ, bfile, &game, &msize, &mkey, 0) != OK)
  574.     {
  575.     qprintf("Game %d not found.\r", gamenum);
  576.     }
  577.     else
  578.     {
  579.     if (btrv(b_delete, bfile, &game, &msize, &mkey, 0) == OK)
  580.     {
  581.         send("Game deleted.\r");
  582.     }
  583.     else
  584.     {
  585.         qprintf("Error deleting game %d\n", gamenum);
  586.     }
  587.     }
  588.     btrv(b_close, bfile, &game, &msize, &mkey, 0);
  589. }
  590.  
  591. setplayer(char *s, int num)
  592. {
  593.     int siz;
  594.     int j;
  595.     int bfile, msize;
  596.     ENTRY akey;
  597.  
  598.     if ((bfile = btrv(b_open, -1, "croswits.idx", &msize, (ENTRY *) "croswits.dat", 1)) < 0)
  599.     bfile = btrv(b_create, -1, "croswits.idx", &msize, (ENTRY *) "croswits.dat", 1);
  600.  
  601.     if (bfile < 0)
  602.     {
  603.     send("Unable to save game information in database! Code = 110\r");
  604.     return;
  605.     }
  606.  
  607.     sprintf(akey.key, "!%s", s);
  608.     siz = sizeof(struct xwit_player_rec);
  609.     if (btrv(b_getequ, dbfile, &aplayer, &siz, &akey, 1) != OK)
  610.     {
  611.     memset(&aplayer, 0, sizeof(struct xwit_player_rec));
  612.     sprintf(akey.key, "!%s", s);
  613.     strcpy(aplayer.name, s);
  614.     siz = sizeof(struct xwit_player_rec);
  615.     btrv(b_insert, dbfile, &aplayer, &siz, &akey, 1);
  616.     }
  617.     for (j = 0; j < 40 && aplayer.games[j]; j++);
  618.     if (j < 40)
  619.     {
  620.     aplayer.games[j] = num;
  621.     sprintf(aplayer.name, "!%s", s);
  622.     strcpy(akey.key, aplayer.name);
  623.     siz = sizeof(struct xwit_player_rec);
  624.     btrv(b_update, dbfile, &aplayer, &siz, &akey, 1);
  625.     }
  626.     btrv(b_close, bfile, &game, &msize, &mkey, 0);
  627. }
  628.